<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=sc, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //1-100所以质数
        var isPrime;
        for(var i = 2; i<=100; i++){
            isPrime=true;
            for(var j=2;j<i;j++){
                if(i%j==0){
                    isPrime=false;
                }
            }
            if(isPrime){
                document.write(i+"<br>");
            }
        }

        //判断一个字符串是否为一个有效的手机号码
        function checkPhone(phone){
            if(phone.length!=11){
                return false;
            }
            for(var i=0;i<phone.length;i++){
                var code = phone.charCodeAt(i);
                if(code < 48 || code > 57){
                    return false;
                }
            }
            if(phone[0]!=1){
                return false;
            }
            if(!(phone[1]>=3 && phone[1]<=9)){
                return false;
            }

            return true;

        }

        function checkPhoneRe(phone){
            var re = new RegExp("^1[3-9]\\d{9}$");
            return re.test(phone);
        }

        var phone = window.prompt("请输入一串手机号码");
        document.write("手机号码："+ checkPhone(phone)+"<br>");
        document.write("正则 手机号码："+ checkPhoneRe(phone)+"<br>");


        function checkNumber(value){
            var re1 = new RegExp('^[-\\d]\\d*\\.?\\d*$')
            var re2 = new RegExp('^[-\\.\\d]\\d*$')
            var result = re1.test(value) || re2.test(value);
            return result;
        }

        function testCheckNumber(value,result){
            if(checkNumber(value)==result){
                document.write("测试成功<br>");
            }else{
                document.write("测试失败，测试数据为:"+value+"<br>");
            }
        }

        testCheckNumber('--0.123',false);
        testCheckNumber('-0.123',true);
        testCheckNumber('0.123',true);
        testCheckNumber('0..123',false);
        testCheckNumber('0.123-',false);
        testCheckNumber('123',true);
        testCheckNumber('112a',false);
        testCheckNumber('.112',true);
        testCheckNumber('111.',true);
        testCheckNumber('..11',false);

        function checkTel(tel){
            var re =new RegExp('^0\\d{2,3}-\\d{7,8}$')
            document.write(re.test(tel));
        }

        //^[a-z0-9]{1,30}[-_\\.]?[a-z0-9]{1,30}@[a-z0-9]*\\.?[a-z0-9]+(\\.[a-z]{2,4}){1,2}
    </script>
</body>
</html>